﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace MicropleSoft.Controls
{
    public partial class XComboBoxEdit : DevExpress.XtraEditors.ComboBoxEdit, IDataBinder
    {
        public XComboBoxEdit()
        {
            InitializeComponent();
        }

        public void ExcuteDataBinding(WmsApp.Library.IBaseDomainObject baseDomainObject)
        {
            if (String.IsNullOrEmpty(PropertyName))
            {
                throw new PropertyNameNotInitializedException();
            }

            if (baseDomainObject == null)
            {
                throw new ArgumentNullException("baseDomainObject");
            }

            var propertyInfo = baseDomainObject.GetType().GetProperty(PropertyName);
            if (propertyInfo == null)
            {
                //throw new PropertyNotExistException();
                return;
            }

            this.DataBindings.Clear();
            this.DataBindings.Add("EditValue", baseDomainObject, PropertyName);

        }

        public string PropertyName { get; set; }

        [DefaultValue(false)]
        public bool IsPrimaryKey { get; set; }

        public bool ReadOnly
        {
            get
            {
                return this.Properties.ReadOnly;
            }
            set
            {
                this.Properties.ReadOnly = value;
            }
        }
    }
}
